package cn.silver.framework.core.exception;

import cn.silver.framework.openapi.constant.ResultEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serial;

/**
 * 业务异常
 *
 * @author ruoyi
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "ServiceException", title = "业务异常对象")
public final class ServiceException extends RuntimeException {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    @Schema(title = "错误码")
    private Integer code;

    /**
     * 错误提示
     */
    @Schema(title = "错误提示")
    private String message;

    /**
     * 错误明细，内部调试错误
     */
    @Schema(title = "错误明细，内部调试错误")
    private String detailMessage;

    public ServiceException(String message) {
        this.code = ResultEnum.ERROR.getCode();
        this.message = message;
    }

    public ServiceException(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
}
